var app = new Vue({
    el: '#app',
    data: {
        form: {
            title: '',
            subtitle: '',
            date: '',
            time: '08:00',
            number: '',
            id: '',
            data: {
                one: '',
                two: '',
                three: '',
                four: '',
                five: '',
                six: '',
                seven: '',
                type: 'left',
                id: ''
            },
            leftData: [],
            rightData: [],
        },
        table: {
            list: []
        },
        pageInfo: {
            title: '栏目'
        },
        dialog: {
            timeIsShow: false,
            dateIsShow: false,
            isShow: false,
            dataIsShow: false,
            title: '',
            disabled: false
        },
        ssqDetail: {
            id: ''
        },
        activeName: 'first',
        activeNameTwo: 'left'
    },
    mounted:function(){
        this.ssqDetail.id = this.form.id = this.getUrlKey('id');
        this.getCate()
    },
    methods: {
        goBack: function() {
            window.location.href = '/ssq/index';
        },
        getCate: function() {
            var _this = this;
            // 获取栏目
            $.ajax({
                url: '/ssq/getOne',
                type: 'get',
                data: {id: _this.ssqDetail.id},
                dataType: 'json',
                success: function(res) {
                    if (res.status === 0) {
                        _this.ssqDetail = res.data
                        _this.form.title = res.data.title
                        _this.form.subtitle = res.data.subtitle
                        _this.form.leftData = res.data.leftData
                        _this.form.rightData = res.data.rightData
                    } else {
                        _this.$message.error(res.message)
                    }
                }
            })
        },
        generateTitle: function() {
            this.dialog.timeIsShow = true;
        },
        generateSubtitle: function(){
            this.dialog.dateIsShow = true;
        },
        addData: function(){
            this.form.data = {
                one: '',
                two: '',
                three: '',
                four: '',
                five: '',
                six: '',
                seven: '',
                type: 'left',
                id: ''
            };
            this.dialog.dataIsShow = true;
        },
        timeSubmit: function(){
            if (this.form.number != null && this.form.number !== "") {
                this.form.title = '双色球第' + this.form.number + '期中奖号码'
                this.dialog.timeIsShow = false;
            } else {
                this.$message.error('请输入期数');
            }
        },
        dateSubmit: function(){
            if (this.form.time != null && this.form.time !== "") {
                this.form.time += ':00'
            }
            if (this.form.date != null && this.form.date !== "") {
                this.form.subtitle = '开奖时间：' + this.form.date + ' ' + this.form.time
                this.dialog.dateIsShow = false;
            } else {
                this.$message.error('请选择日期');
            }
        },
        onSubmit: function(){
            var _this = this;
            if (_this.form.title === '') {
                _this.$message.error('主标题不能为空');return false;
            }
            if (_this.form.subtitle === '') {
                _this.$message.error('副标题不能为空');return false;
            }
            // 修改标题
            $.ajax({
                url: '/ssq/save',
                type: 'post',
                data: _this.form,
                dataType: 'json',
                success: function(res) {
                    if (res.status === 0) {
                        _this.$message.success(res.message)
                    } else {
                        _this.$message.error(res.message)
                    }
                }
            })
        },
        dataSubmit: function() {
            var _this = this;
            if (_this.form.data.one === '') {
                _this.$message.err('第一个数字不能为空');return false;
            }
            if (_this.form.data.two === '') {
                _this.$message.err('第二个数字不能为空');return false;
            }
            if (_this.form.data.three === '') {
                _this.$message.err('第三个数字不能为空');return false;
            }
            if (_this.form.data.four === '') {
                _this.$message.err('第四个数字不能为空');return false;
            }
            if (_this.form.data.five === '') {
                _this.$message.err('第五个数字不能为空');return false;
            }
            if (_this.form.data.six === '') {
                _this.$message.err('第六个数字不能为空');return false;
            }
            if (_this.form.data.seven === '') {
                _this.$message.err('第七个数字不能为空');return false;
            }
            _this.form.data.cate_id = _this.ssqDetail.id;
            $.ajax({
                url: '/ssq/saveData',
                type: 'post',
                data: _this.form.data,
                dataType: 'json',
                success: function(res) {
                    if (res.status === 0) {
                        _this.dialog.dataIsShow = false;
                        _this.getCate();
                        _this.$message.success(res.message);
                        _this.form.data = {
                            one: '',
                            two: '',
                            three: '',
                            four: '',
                            five: '',
                            six: '',
                            seven: '',
                            type: 'left',
                            id: ''
                        };
                    } else {
                        _this.$message.error(res.message)
                    }
                }
            })
        },
        deleteData: function(id) {
            var _this = this;
            _this.$confirm('是否删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 处理删除逻辑
                $.ajax({
                    url: '/ssq/delData',
                    type: 'post',
                    data: {id: id},
                    dataType: 'json',
                    success: function(res) {
                        if (res.status === 0) {
                            _this.$message.success(res.message)
                            _this.getCate()
                        } else {
                            _this.$message.error(res.message)
                        }
                    }
                })
            }).catch(() => {

            });

        },
        editData: function(item) {
            this.form.data = item
            this.dialog.dataIsShow = true;
        },
        generateShare: function() {
            var _this = this
            $.ajax({
                url: '/ssq/generateShare',
                type: 'post',
                data: {cate_id: _this.ssqDetail.id},
                dataType: 'json',
                success: function(res) {
                    if (res.status === 0) {
                        window.location.href = '/ssq/share?uuid=' + res.data.uuid;
                    } else {
                        _this.$message.error(res.message)
                    }
                }
            })
        },
        copyCate: function() {
            var _this = this;
            _this.$prompt('请输入栏目名称', '栏目', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputValue:'',
            }).then(({value}) => {
                if (value != null && value !== "") {
                    console.log(value)
                    // 修改栏目
                    $.ajax({
                        url: '/ssq/copyCate',
                        type: 'post',
                        data: {name: value, id: _this.ssqDetail.id},
                        dataType: 'json',
                        success: function(res) {
                            if (res.status === 0) {
                                _this.$message.success(res.message)
                            } else {
                                _this.$message.error(res.message)
                            }
                        }
                    })
                } else {
                    _this.$message({
                        type: 'warning',
                        message: '未输入任何信息'
                    })
                }
            }).catch(() => {

            })
        },
        delData: function() {
            var _this = this;
            _this.$confirm('是否删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 处理删除逻辑
                $.ajax({
                    url: '/ssq/deleteData',
                    type: 'post',
                    data: {id: _this.ssqDetail.id},
                    dataType: 'json',
                    success: function(res) {
                        if (res.status === 0) {
                            _this.$message.success(res.message)
                            _this.getCate()
                        } else {
                            _this.$message.error(res.message)
                        }
                    }
                })
            }).catch(() => {

            });
        },

    }
});
$(document).keyup(function(e){
    var key = e.which;
    if(key==13){
        app.getCommunityList();
        return false;
    }
});
